﻿local pack_list = {} ---@type Package[]

--- 从扩展包里读取技能skel
---@param package Package
local function loadSkillSkelsFromPackage (package)
  local path = "./packages/moepack/pkg/"..package.name.."/skills"
  if not FileIO.isDir(path) then return end -- 如果没有skills文件夹就不加载了
  local skels = {}
  local normalized_dir = path
      :gsub("^%.+/", "")
      :gsub("/+$", "")
      :gsub("/", ".")
  for _, filename in ipairs(FileIO.ls(path)) do
    -- 下划线开头的文件不会被加载
    if filename:sub(-4) == ".lua" and filename ~= "init.lua" and not filename:startsWith("_") then
      local skel = Pcall(require, normalized_dir .. "." .. filename:sub(1, -5))
      if skel then
        -- 如果返回了一个skel表
        if type(skel) == "table" and skel[1] ~= nil then
          for _, v in ipairs(skel) do
            table.insert(skels, v)
          end
        else
          table.insert(skels, skel)
        end
      end
    end
  end
  package:loadSkillSkels(skels)
end

-- 加载所有拓展包，并为包加载技能
local package_path = "packages/moepack/pkg"
local normalized_dir = "packages.moepack.pkg."
for _, dirname in ipairs(FileIO.ls(package_path)) do
  if FileIO.isDir(package_path .. "/" .. dirname) then
    local pkg = Pcall(require, normalized_dir.. dirname)---@type Package
    if pkg then
      loadSkillSkelsFromPackage(pkg)
      table.insert(pack_list, pkg)
    end
  end
end


Fk.translations["zh_CN"] = Fk.translations["zh_CN"] or {}

-- 为本扩展包所有武将填写默认设计者
for _, pack in ipairs(pack_list) do
  for _, g in ipairs(pack.generals) do
    local str = "designer:"..g.name
    if not Fk.translations["zh_CN"][str] then
      Fk.translations["zh_CN"][str] = "EmoPrincess"
    end
  end
end

Fk:loadTranslationTable{
  ["moepack"] = "萌包",
  ["moe"] = "萌",
}

Fk:appendKingdomMap("god", {"moe"})

Fk:loadTranslationTable{
  ["#emo-getcard"] = "选择获得的牌",
}

return pack_list
